home *** CD-ROM | disk | FTP | other *** search
- #include <egb.h>
- #include <mos.h>
- #include <time.h>
- #include <stdio.h>
- #include <fmcfrb.h>
- #include <msdos.cf>
- #include <stdlib.h>
- #include <string.h>
- #include "define.h"
- #include "extend.h"
-
- #define BS 8
- #define RET 0xd
- #define SORT_MAX 2048
- #define BUTTON_COL_1 8
- #define BUTTON_COL_2 15
- #define IMAGE_NUMBER_MAX 11
-
- static char *image_buff[IMAGE_NUMBER_MAX];
-
- // マウスカーソル形状設定関数
- void mouse_type( char *pat_work, int n )
- {
-
- UCHAR ptn, data[ ] = { 136, 248, 143, 255 };
- int i, j;
-
- MOS_typeRom( n, 0, 0, pat_work );
- for( i=130;i<=258;i++ )
- *( pat_work + i + 384 ) = *( pat_work + i );
- for( i=127;i>=0;i-- ){
- ptn = *( pat_work + i+2 );
- for( j=0;j<4;j++ )
- *( pat_work + 2+i*4+j ) = data[ (ptn>>((3-j)*2)) & 3 ];
- }
-
- }
- // 点描画関数
- void pset( char *egbwork, int x1, int y1, int c )
- {
-
- struct {
- short n, m1, m2;
- } mark = { 1, 0, 0 };
-
- mark.m1 = x1;
- mark.m2 = y1;
- EGB_color( egbwork, 0, c );
- EGB_pset( egbwork, ( char *)&mark );
-
- }
- // 直線描画関数
- void line( char *egbwork, int x1, int y1, int x2, int y2, int c )
- {
-
- struct {
- short n, m1, m2, m3, m4;
- } mark = { 2, 0, 0, 0, 0 };
-
- mark.m1 = x1;
- mark.m2 = y1;
- mark.m3 = x2;
- mark.m4 = y2;
- EGB_color( egbwork, 0, c );
- EGB_connect( egbwork, ( char *)&mark );
-
- }
- // 枠線描画関数
- void frame( char *egbwork, int x1, int y1, int x2, int y2, int c )
- {
-
- struct {
- short m1, m2, m3, m4;
- } mark;
-
- mark.m1 = x1;
- mark.m2 = y1;
- mark.m3 = x2;
- mark.m4 = y2;
- EGB_color( egbwork, 0, c );
- EGB_paintMode( egbwork, 2 );
- EGB_rectangle( egbwork, ( char *)&mark );
-
- }
- // 矩形描画関数
- void box( char *egbwork, int x1, int y1, int x2, int y2, int c )
- {
-
- struct {
- short x1, y1, x2, y2;
- } mark;
-
- mark.x1 = x1;
- mark.y1 = y1;
- mark.x2 = x2;
- mark.y2 = y2;
- EGB_color( egbwork, 0, c );
- EGB_color( egbwork, 2, c );
- EGB_paintMode( egbwork, 0x22 );
- EGB_rectangle( egbwork, ( char *)&mark );
-
- }
- // ペイント関数
- void paint( char *egbwork, int x, int y, int c )
- {
-
- struct {
- short x, y;
- } mark;
-
- mark.x = x;
- mark.y = y;
- EGB_color( egbwork, 0, c );
- EGB_color( egbwork, 2, c );
- EGB_paintMode( egbwork, 0x22 );
- EGB_closePaint( egbwork, ( char *)&mark );
-
- }
- // ボタン表示関数
- void button_off( char *egbwork, int x1, int y1, int x2, int y2 )
- {
-
- struct {
- short n, x1, y1, x2, y2;
- } line = { 2, 0, 0, 0, 0 };
-
- EGB_color( egbwork, 0, BUTTON_COL_2 );
- line.x1 = x1 , line.y1 = y1;
- line.x2 = x1 , line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1+1, line.y1 = y1;
- line.x2 = x1+1, line.y2 = y2-1;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1 , line.y1 = y1;
- line.x2 = x2 , line.y2 = y1;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1 , line.y1 = y1+1;
- line.x2 = x2-1, line.y2 = y1+1;
- EGB_connect( egbwork, (char *)&line );
- EGB_color( egbwork, 0, BUTTON_COL_1 );
- line.x1 = x1+1, line.y1 = y2;
- line.x2 = x2 , line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1+2, line.y1 = y2-1;
- line.x2 = x2 , line.y2 = y2-1;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x2-1, line.y1 = y1+2;
- line.x2 = x2-1, line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x2 , line.y1 = y1+1;
- line.x2 = x2 , line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
-
- }
- // ボタン表示関数
- void button_on( char *egbwork, int x1, int y1, int x2, int y2 )
- {
-
- struct {
- short n, x1, y1, x2, y2;
- } line = { 2, 0, 0, 0, 0 };
-
- EGB_color( egbwork, 0, BUTTON_COL_1 );
- line.x1 = x1 , line.y1 = y1;
- line.x2 = x1 , line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1+1, line.y1 = y1;
- line.x2 = x1+1, line.y2 = y2-1;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1 , line.y1 = y1;
- line.x2 = x2 , line.y2 = y1;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1 , line.y1 = y1+1;
- line.x2 = x2-1, line.y2 = y1+1;
- EGB_connect( egbwork, (char *)&line );
- EGB_color( egbwork, 0, BUTTON_COL_2 );
- line.x1 = x1+1, line.y1 = y2;
- line.x2 = x2 , line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x1+2, line.y1 = y2-1;
- line.x2 = x2 , line.y2 = y2-1;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x2-1, line.y1 = y1+2;
- line.x2 = x2-1, line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
- line.x1 = x2 , line.y1 = y1+1;
- line.x2 = x2 , line.y2 = y2;
- EGB_connect( egbwork, (char *)&line );
-
- }
- // 時間待ち関数
- void sleep( int n )
- {
-
- clock_t start;
-
- start = clock( );
- while( clock( ) - start<=n );
-
- }
- int font_start( char *str_ptn, char *path )
- {
-
- FILE *fp;
-
- if( ( fp = fopen( path, "rb" ) )==NULL )
- return( -1 );
- fread( str_ptn, 1, 110592, fp );
- fclose( fp );
- return( 0 );
-
- }
- // イメージ格納関数
- int getimage( char *egbwork, int x1, int y1, int x2, int y2, int n )
- {
-
- int page_0, page_1, d_mode;
- USHORT egb_sel;
- struct {
- char *ptn;
- short ds, x1, y1, x2, y2;
- } image = { NULL, 0x14, 0, 0, 0, 0 };
-
- n %= IMAGE_NUMBER_MAX; // 10番は通常ファイルセレクタが使う
- egb_sel = getds( );
- EGB_getResolution( &page_0, &page_1 );
- d_mode = EGB_getWritePage( egbwork, egb_sel );
-
- if( !d_mode ){
- if( page_0<=4 )
- image_buff[ n ] = malloc( ( x2-x1+8 ) / 8 * 4 * ( y2-y1+1 ) );
- else if( page_0>=5 && page_0<=11 )
- image_buff[ n ] = malloc( ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) * 2 );
- else if( page_0>=12 && page_0<=14 )
- image_buff[ n ] = malloc( ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) );
- else
- image_buff[ n ] = malloc( ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) * 2 );
- }
- else {
- if( page_1<=4 )
- image_buff[ n ] = malloc( ( x2-x1+8 ) / 8 * 4 * ( y2-y1+1 ) );
- else if( page_1>=5 && page_1<=11 )
- image_buff[ n ] = malloc( ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) * 2 );
- else if( page_1>=12 && page_1<=14 )
- image_buff[ n ] = malloc( ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) );
- else
- image_buff[ n ] = malloc( ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) * 2 );
- }
- if( image_buff[ n ]==NULL )
- return( -1 );
- image.ptn = image_buff[ n ];
- image.x1 = x1;
- image.y1 = y1;
- image.x2 = x2;
- image.y2 = y2;
- EGB_getBlock( egbwork, ( char *)&image );
- return( 0 );
-
- }
- // イメージ復帰関数
- void putimage( char *egbwork, int x1, int y1, int x2, int y2, int n )
- {
-
- struct {
- char *ptn;
- short ds, x1, y1, x2, y2;
- } image = { NULL, 0x14, 0, 0, 0, 0 };
-
- image.ptn = image_buff[ n % IMAGE_NUMBER_MAX ];
- image.x1 = x1;
- image.y1 = y1;
- image.x2 = x2;
- image.y2 = y2;
- EGB_putBlock( egbwork, 0, ( char *)&image );
- free( image_buff[ n ] );
-
- }
- // パレット設定関数
- void palette( char *egbwork, int c, int b, int r, int g )
- {
-
- struct {
- int num;
- int c_num;
- char b, r, g, zero;
- } pal = { 1, 0, 0, 0, 0, 0 };
-
- pal.c_num = c;
- pal.b = b;
- pal.r = r;
- pal.g = g;
- EGB_palette( egbwork, 1, ( char *)&pal );
-
- }
- // TMENUパレット設定関数
- void tmenu_pal( char *egbwork )
- {
-
- palette( egbwork, 1, 8*16, 1*16, 11*16 );
- palette( egbwork, 2, 12*16, 9*16, 13*16 );
- palette( egbwork, 3, 15*16, 7*16, 6*16 );
- palette( egbwork, 4, 12*16, 9*16, 10*16 );
-
- }
- // 文字列ソート関数
- void sort_string( char *str[ ], int n )
- {
-
- char *buff_a;
- int i, j;
-
- for( j=0;j<=n-2;j++ ){
- for( i=0;i<=n-2-j;i++ ){
- if( strcmp( str[ i ], str[ i+1 ] )>=1 ){
- buff_a = str[ i+1 ];
- str[ i+1 ] = str[ i ];
- str[ i ] = buff_a;
- }
- }
- }
-
- }
- // 数値列ソート関数(大きい順)
- void sort_num_upper( int *num, int n )
- {
-
- int i, j, dummy;
-
- for( j=0;j<=n-2;j++ ){
- for( i=0;i<=n-2-j;i++ ){
- if( *( num + i )<*( num + i+1 ) )
- swap( *( num + i ), *( num + i+1 ), dummy )
- }
- }
-
- }
- // 数値列ソート関数(小さい順)
- void sort_num_lower( int *num, int n )
- {
-
- int i, j, dummy;
-
- for( j=0;j<=n-2;j++ ){
- for( i=0;i<=n-2-j;i++ ){
- if( *( num + i )>*( num + i+1 ) )
- swap( *( num + i ), *( num + i+1 ), dummy )
- }
- }
-
- }
- // 逆写像ソート
- int reverse_sort_lower( int *num, int n )
- {
-
- int i, j, k, *p;
- int max_element = 16384 * 10; // 要素の最大値を決定する
-
- if( ( p = ( int *)calloc( max_element, 4 ) )==NULL )
- return( -1 );
- for( i=0;i<=n-1;i++ )
- ( *( p + *( num + i ) ) )++;
- k = 0;
- for( i=0;i<=max_element-1;i++ ){
- if( *( p + i ) ){
- for( j=0;j<=*( p + i )-1;j++ )
- *( num + j+k ) = i;
- k += j;
- }
- }
- free( p );
- return( 0 );
-
- }
- int reverse_sort_upper( int *num, int n )
- {
-
- int i, j, k, *p;
- int max_element = 16384 * 10; // 要素の最大値を決定する
-
- if( ( p = ( int *)calloc( max_element, 4 ) )==NULL )
- return( -1 );
- for( i=0;i<=n-1;i++ )
- ( *( p + *( num + i ) ) )++;
- k = 0;
- for( i=max_element-1;i>=0;i-- ){
- if( *( p + i ) ){
- for( j=0;j<=*( p + i )-1;j++ )
- *( num + j+k ) = i;
- k += j;
- }
- }
- free( p );
- return( 0 );
-
- }
- // キー入力関数
- int key_read( int *key, int r )
- {
-
- char matrix[ 16 ];
- static char map[ ] = { /* Cap on and Shift Off */
- 0, 0, '1', '2', '3', '4', '5', '6',
- '7', '8', '9', '0', '-', '^','\\', 8,
- 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U',
- 'I', 'O', 'P', '@', '[', 13, 'A', 'S',
- 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';',
- ':', ']', 'Z', 'X', 'C', 'V', 'B', 'N',
- 'M', ',', '.', '/', '"', ' ', '*', '/',
- '+', '-', '7', '8', '9', '=', '4', '5',
- '6', 0, '1', '2', '3', 13, '0', '.',
- 0, 0, 0, 0, 0, 30, 0, 29,
- 31, 28, 0, 128, 0, 129, 0, 0,
- 0, 0, 130, 0, 0, 0, 0, 0,
- /* Cap On or Shift on */
- 0, 0, '!', '"', '#', '$', '%', '&',
- 39, '(', ')', 0, '=', '~', '|', 0,
- 0, 'q', 'w', 'e', 'r', 't', 'y', 'u',
- 'i', 'o', 'p', '`', '{', 13, 'a', 's',
- 'd', 'f', 'g', 'h', 'j', 'k', 'l', '+',
- '*', '}', 'z', 'x', 'c', 'v', 'b', 'n',
- 'm', '<', '>', '?', '_', ' ', '*', '/',
- '+', '-', '7', '8', '9', '=', '4', '5',
- '6', 0, '1', '2', '3', 13, '0', '.',
- 0, 0, 0, 0, 0, 30, 0, 29,
- 31, 28, 0, 128, 0, 129, 0, 0,
- 0, 0, 130, 0, 0, 0, 0, 0,
- /* Cap Off or Shift Off */
- 0, 0, '1', '2', '3', '4', '5', '6',
- '7', '8', '9', '0', '-', '^','\\', 8,
- 0, 'q', 'w', 'e', 'r', 't', 'y', 'u',
- 'i', 'o', 'p', '@', '[', 13, 'a', 's',
- 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
- ':', ']', 'z', 'x', 'c', 'v', 'b', 'n',
- 'm', ',', '.', '/', '"', ' ', '*', '/',
- '+', '-', '7', '8', '9', '=', '4', '5',
- '6', 0, '1', '2', '3', 13, '0', '.',
- 0, 0, 0, 0, 0, 30, 0, 29,
- 31, 28, 0, 128, 0, 129, 0, 0,
- 0, 0, 130, 0, 0, 0, 0, 0,
- /* Cap Off or Shift On */
- 0, 0, '!', '"', '#', '$', '%', '&',
- 39, '(', ')', 0, '=', '~', '|', 0,
- 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U',
- 'I', 'O', 'P', '`', '{', 13, 'A', 'S',
- 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+',
- '*', '}', 'Z', 'X', 'C', 'V', 'B', 'N',
- 'M', '<', '>', '?', '_', ' ', '*', '/',
- '+', '-', '7', '8', '9', '=', '4', '5',
- '6', 0, '1', '2', '3', 13, '0', '.',
- 0, 0, 0, 0, 0, 30, 0, 29,
- 31, 28, 0, 128, 0, 129, 0, 0,
- 0, 0, 130, 0, 0, 0, 0, 0,
- /* Kana On */
- 0, 0, 'ヌ', 'フ', 'ア', 'ウ', 'エ', 'オ',
- 'ヤ', 'ユ', 'ヨ', 'ワ', 'ホ', 'ヘ', 'ー', 8,
- 0, 'タ', 'テ', 'イ', 'ス', 'カ', 'ン', 'ナ',
- 'ニ', 'ラ', 'セ', '゙', '゚', 13, 'チ', 'ト',
- 'シ', 'ハ', 'キ', 'ク', 'マ', 'ノ', 'リ', 'レ',
- 'ケ', 'ム', 'ツ', 'サ', 'ソ', 'ヒ', 'コ', 'ミ',
- 'モ', 'ネ', 'ル', 'メ', 'ロ', ' ', '*', '/',
- '+', '-', '7', '8', '9', '=', '4', '5',
- '6', 0, '1', '2', '3', 13, '0', '.',
- 0, 0, 0, 0, 0, 30, 0, 29,
- 31, 28, 0, 128, 0, 129, 0, 0,
- 0, 0, 130, 0, 0, 0, 0, 0,
- /* Kana On and Shift + */
- 0, 0, 0, 0, 'ァ', 'ゥ', 'ェ', 'ォ',
- 'ャ', 'ュ', 'ョ', 'ヲ', 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, '「', 13, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, '」', 'ッ', 0, 0, 0, 0, 0,
- 0, '、', '。', '・', 0, ' ', '*', '/',
- '+', '-', '7', '8', '9', '=', '4', '5',
- '6', 0, '1', '2', '3', 13, '0', '.',
- 0, 0, 0, 0, 0, 30, 0, 29,
- 31, 28, 0, 128, 0, 129, 0, 0,
- 0, 0, 130, 0, 0, 0, 0, 0 };
- int i = 0, j = 0, flag = 0;
- UINT encode;
- static int key_mode[2];
-
- encode = KYB_shift( );
- key_mode[ 0 ] = ( encode & 0x01 ) ? 1 : 0;
- key_mode[ 1 ] = ( encode & 0x02 ) ? 1 : 0;
- KYB_matrix( matrix );
- KYB_clrbuf( );
- *key = key_mode[ 0 ] + key_mode[ 1 ] * 2;
- if( matrix[ 10 ] & 0x08 ){
- KYB_clrbuf( );
- KYB_matrix( matrix );
- flag = 1;
- }
- if( matrix[ 10 ] & 0x20 ){
- KYB_matrix( matrix );
- while( matrix[ 10 ] & 0x20 )
- KYB_matrix( matrix );
- KYB_clrbuf( );
- encode = KYB_shift( );
- key_mode[ 0 ] = ( encode & 0x01 ) ? 1 : 0;
- key_mode[ 1 ] = ( encode & 0x02 ) ? 1 : 0;
- *key = key_mode[ 0 ] + key_mode[ 1 ] * 2;
- return( 0 );
- }
- if( matrix[ 11 ] & 0x04 ){
- KYB_matrix( matrix );
- while( matrix[ 11 ] & 0x04 )
- KYB_matrix( matrix );
- KYB_clrbuf( );
- encode = KYB_shift( );
- key_mode[ 0 ] = ( encode & 0x01 ) ? 1 : 0;
- key_mode[ 1 ] = ( encode & 0x02 ) ? 1 : 0;
- *key = key_mode[ 0 ] + key_mode[ 1 ] * 2;
- return( 0 );
- }
- while( i<=11 && !matrix[ i ] )
- i++;
- if( i>=12 )
- return( 0 );
- while( !( matrix[ i ] & 0x01 ) ){
- matrix[ i ] >>= 1;
- j++;
- }
- if( i==10 && j==3 )
- return( 0 );
- if( i+j ){
- if( !r ){
- KYB_matrix( matrix );
- while( matrix[ i ] & ( 1 << j ) )
- KYB_matrix( matrix );
- }
- else
- sleep( 2 );
- KYB_clrbuf( );
- }
- else
- return( 0 );
- if( !flag && key_mode[ 0 ] && !key_mode[ 1 ] )
- return( ( int )map[ i*8+j ] );
- else if( flag && key_mode[ 0 ] && !key_mode[ 1 ] )
- return( ( int )map[ 0x60+i*8+j ] );
- else if( !flag && !key_mode[ 0 ] && !key_mode[ 1 ] )
- return( ( int )map[ 0xc0+i*8+j ] );
- else if( flag && !key_mode[ 0 ] && !key_mode[ 1 ] )
- return( ( int )map[ 0x120+i*8+j ] );
- else if( !flag && key_mode[ 1 ] )
- return( ( int )map[ 0x180+i*8+j ] );
- else
- return( ( int )map[ 0x1e0+i*8+j ] );
-
- }
- // ディスク状態収得関数
- void disk_status( int n, int *not, int *pro )
- {
-
- UINT s;
-
- DKB_setmode( 0x20+n, 0x0003, 0x0208 );
- DKB_rdstatus( 0x20+n, &s );
- *not = s & 0x01;
- *pro = s & 0x02;
-
- }
- // マウスループ
- void mos_loop( int n )
- {
-
- int ch;
-
- do{
- MOS_rdpos( &ch, 0, 0 );
- }while( ch==n );
-
- }
- // マウスループ
- void mos_loop_not( int n )
- {
-
- int ch;
-
- do{
- MOS_rdpos( &ch, 0, 0 );
- }while( ch!=n );
-
- }
-